﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
using Sunny.UI;

namespace pinduoduo.Page
{
    public partial class SettingPage : UIPage
    {
        public SettingPage()
        {
            InitializeComponent();
        }

        private async void uiButton1_Click(object sender, EventArgs e)
        {
            if (ShowAskDialog("请确认机器码是否正确，一旦换绑成功，本软件自动退出，是否继续？"))
            {

                var res = await G_Api.UpdateMachineCode(MachineCodeTextBox.Text.Replace("\0", "").Replace("\r\n", ""));
                if (res.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var jo = JObject.Parse(res.Content);
                    if (jo["code"].ToString() == "200")
                    {
                        ShowSuccessDialog("换绑成功");
                        this.BeginInvoke(new Action(() =>
                        {
                            this.Close();
                        }));
                        System.Environment.Exit(0);
                    }
                    else
                    {
                        ShowSuccessNotifier(jo["msg"].ToString());
                    }
                }
            }
        }
    }
}
